package com.emergency.embackend.controller;

import com.emergency.embackend.common.R;
import com.emergency.embackend.entity.QuizType;
import com.emergency.embackend.service.QuizDataService;
import com.emergency.embackend.service.QuizTypeService;
import com.emergency.embackend.utils.UserHolder;
import com.emergency.embackend.vo.QuizTypeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/quiz/type")
public class QuizTypeController {
    @Autowired
    private QuizTypeService quizTypeService;
    @Autowired
    private QuizDataService quizDataService;
    @GetMapping("getType")
    public R getType(){
        List<QuizTypeVO> type = quizTypeService.getType();
        return R.ok().put("data",type);
    }
    @PostMapping("/update")
    public R update(@RequestBody QuizType quizType){
        if(quizType==null){
            return R.error("参数不允许为空！");
        }
        quizTypeService.update(quizType);
        return R.ok();
    }
    @GetMapping("/delete")
    public R delete(@RequestParam("typeId") Long typeId){
        if(typeId==null){
            return R.error(500,"请找管理员！");
        }
        quizTypeService.delete(typeId);
        quizDataService.deleteByTypeId(typeId);
        return R.ok();
    }
    @PostMapping("/add")
    public R add(@RequestBody QuizType quizType){
        if(quizType==null){
            return R.error("参数不允许为空！");
        }
        quizTypeService.add(quizType);
        return R.ok();
    }

}
